package ui.observ;

import java.util.HashMap;
import java.util.Observable;

import datatypes.Edge;
import datatypes.GuiAction;
import datatypes.GuiActionType;
import datatypes.Host;

public class PhysicalNetworkObservableUnit extends Observable {

	//BEGIN "SINGLETON"
	private static HashMap <Integer, PhysicalNetworkObservableUnit> instanceMap = new HashMap <Integer, PhysicalNetworkObservableUnit>();

	private PhysicalNetworkObservableUnit (){
	}

	public static PhysicalNetworkObservableUnit getInstance(int SimulationID){
		if (instanceMap.get(SimulationID)== null){
			instanceMap.put(Integer.valueOf(SimulationID), new PhysicalNetworkObservableUnit());
		}
		return instanceMap.get(SimulationID);
	}
	//END "SINGLETON"
	
	//Helping Methods
	//Methods for inform Observer that something happened
	private void informObserver(GuiAction obj){
		this.setChanged();
		this.notifyObservers(obj);
	}
	
	
	public void edgeAdded (Edge edge){
		this.informObserver(new GuiAction(GuiActionType.NEW_CONNECTION, edge));
	}

	public void edgeRemoved (Edge edge){
		this.informObserver(new GuiAction(GuiActionType.DROP_CONNECTION, edge));
	}
	
	public void nodeAdded (int host){
		this.informObserver(new GuiAction(GuiActionType.NEW_NODE, host));
	}

	public void nodeRemoved (int host){
		this.informObserver(new GuiAction(GuiActionType.DROP_NODE, host));
	}
}
